<template>
  <div class="contain-top">
    <div v-if="isAdmin" class="admin-info">
      {{ user }}
      <button @click="$emit('logout')">退出登陆</button>
    </div>
    <div v-else class="login-button">
      <Item :is-active="false" @active="$emit('clickLogin')">
        <div class="login-left">
          <img src="../assets/sun.png" alt="">
        </div>
        <div class="login-right">登陆</div>
      </Item>
    </div>

    <div class="time">{{ time }}</div>

    <div class="app-title">健康管理系统</div>
  </div>
</template>
<script>
import Item from "./Item";
import DropDownMenu from "@/components/DropDownMenu";

export default {
  name: "TopSpace",
  props: {
    isAdmin: {
      type: Boolean,
      default: false,
    },
    user: {
      type: String,
      default: 'user',
      require: false,
    }
  },
  data() {
    return {
      menuList: [
        {name: "系统设置", id: "0"},
        {name: "退出登陆", id: "1"},
      ],
      time: "",
    }
  },
  components: {
    Item,
    DropDownMenu,
  },
  methods: {
    handlerSelect(select) {
      this.$emit("selectClick", select);
    },
    writeCurrentDate() {
      let date = new Date();
      this.time = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate() + " " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds();
    },
  },
  mounted() {
    setInterval(this.writeCurrentDate, 1000);
  },
  beforeDestroy() {
    clearInterval(this.time)
  }

}
</script>

<style scoped>

.contain-top {
  width: 100%;
  border: 1px solid;
  height: 50px;
  line-height: 50px;
  overflow: hidden;
  display: flex;
  background-color: #f8f6f6;
}

.login-button {
  width: 100px;
  height: 40px;
  position: absolute;
  right: 20px;
  align-self: center;
  text-align: center;
}

.login-right {
  float: right;
  font-size: 15px;
  line-height: 40px;
  margin-right: 20px;
}

.login-left > img {
  height: 100%;
  width: 100%;
}

.login-left {
  float: left;
  width: 25%;
  height: 50%;
  margin-left: 20px;
}

.admin-info {
  position: absolute;
  right: 10px;
  width: 150px;
  margin-right: 10px;
}

.time {
  position: absolute;
  left: 30px;
  font-size: 15px;
  color: #0a0a0a;
}

.app-title {
  position: absolute;
  left: 650px;
  font-family: "KaiTi";
  font-weight: bold;
  font-size: 20px;
}
</style>